<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-fileInfo-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">证件号码：</label>
				<div class="col-sm-8">
					<input id="empId" name="empId" th:value="${baseInfo.empId}" class="form-control" type="text" >
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">姓名：</label>
				<div class="col-sm-8">
					<input id="empNm" name="empNm" th:value="${baseInfo.empNm}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">附件类型：</label>
				<div class="col-sm-8">
					<select id="empAttType" class="form-control m-b" th:with="type=${@dict.getType('pm_att_type')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	                </select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">jpg格式 上传附件：</label>
				<div class="col-sm-8">
					<input id="empAtt" name="empAtt" type="file" class="file" data-show-preview="false">
					<!-- <div class="text-center">
						<button type="button" id="batchSubmit" class="btn btn-primary">导入</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					</div> -->
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "pm/fileInfo"
		$("#form-fileInfo-add").validate({
			rules:{
				empId:{
        			required:true,
        			remote: {
                        url: ctx + "pm/baseInfo/checkEmpIdExist",
                        type: "post",
                        dataType: "json",
                        data: {
                        	name : function() {
                                return $.common.trim($("#empId").val());
                            }
                        },
                        dataFilter: function(data, type) {
                        	return $.validate.exist(data);
                        }
                    }
        		},
        		empNm:{
        			required:true
        		},
        		empAttType:{
        			required:true
        		},
        		empFileNm:{
        			required:true
        		}
        	},
        	messages: {
                "empId": {
                    remote: "该人员的证件号码不存在，请先维护人员基本信息"
                }
            }
		});

        //初始化fileinput控件（第一次初始化）
        function initFileInput(ctrlName, uploadUrl) {
            var control = $('#' + ctrlName);
            control.fileinput({
                language: 'zh',
                uploadUrl: uploadUrl, //上传的地址
                showPreview: false,
                allowedFileExtensions : ['jpg'],//接收的文件后缀
                minFileCount: 1,                                        // 最小上传数量
                maxFileCount: 1,                                        // 最大上传数量
                showUpload: false, //是否显示上传按钮
                showCaption: true,//是否显示标题
                showRemove:false,                                       // 显示移除按钮
                uploadClass:"btn btn-success",                        // 上传按钮样式
                browseClass: "btn btn-primary", //按钮样式
                autoReplace:true,
                enctype: 'multipart/form-data',
                previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
                //enctype:'multipart/form-data',
                validateInitialCount:true,
                uploadExtraData:function(){//向后台传递参数
                    var data={
                        empId:$("#empId").val(),
                        empNm:$("#empNm").val(),
                        empAttType:$("#empAttType").val(),
                        empFileNm:$("#empFileNm").val()
                    };
                    return data;
                }
            })
        }
        initFileInput("empAtt", ctx + "pm/fileInfo/add");
       
		function submitHandler() {
        	
        	 $.modal.confirm("你确定要上传 ?", function() {
                 $('#empAtt').fileinput('upload');


             });
	    }

        $("#empAtt").on("fileuploaded", function(event,data,previewid,index) {
            var result = data.response;
            if (result.code == '0') {
            	 $.operate.saveSuccess(result);
            } else {
                layer.alert(result.msg, {
                    icon: 0,
                    area:['60%','90%'],
                    title: "系统提示",
                }, function (index) {
                    layer.close(index);
                });
            }
            $.modal.closeLoading();
        });
	</script>
</body>
</html>
